#!/bin/bash
set -e

echo "Checking Pyro4..."
echo `easy_install Pyro4==4.18`

if ! $(python -c "import Pyro4" &> /dev/null); then
        echo "Pyro4 not installed, failed to grab from pypi!"
	echo "Please manually install the Pyro4 package."
else
	echo "Pyro4 found, good to go."
fi

running=0
if [ -f /sbin/start ]; then
	if [ -f /etc/init/anybackupserver.conf ]; then
		if [ "`status anybackupserver | grep running | wc -l`" = "1" ]; then
			restart anybackupserver
			running=1
		fi
	fi
else
	if [ -f /etc/init/anybackupserver.conf ]; then
		rm /etc/init/anybackupserver.conf
	fi
	if [ -f /sbin/chkconfig ]; then
		/sbin/chkconfig --add anybackupserver
		/sbin/chkconfig anybackupserver on
	else
		/usr/sbin/update-rc.d anybackupserver defaults
	fi
	if [ -f /etc/init.d/anybackupserver ]; then
		if [ "`service anybackupserver status | grep 'is running' | wc -l`" = "1" ]; then
			service anybackupserver restart
			running=1
		fi
	fi
fi
